package com.adopapa.nezhacloud.authc.domain;

import java.time.Instant;
import java.util.HashMap;
import java.util.Map;

import com.adopapa.nezhacloud.ddd.conf.Comment;
import org.springframework.util.ObjectUtils;

import com.adopapa.nezhacloud.ddd.codegen.CodeGen;
import com.adopapa.nezhacloud.ddd.domain.BaseUuidEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;

@Comment("组织信息")
@Entity
@Table(name = "AUTHC_DEPARTMENT")
public class DepartmentInfo extends BaseUuidEntity {

	private static final long serialVersionUID = 4754307197981917821L;

	@Comment("组织名称")
	@CodeGen(query = "%", form = true, label = "组织名称")
	@Column(name = "DEPT_NAME")
	private String deptName;
	@CodeGen(form = true, label = "备注")
	@Lob
	@Column(name = "REMARK")
	private String remark;

	@Comment("组织代码")
	@CodeGen(query = "%", form = true, label = "组织代码")
	@Column(name = "DEPT_CODE")
	private String deptCode;

	@CodeGen(query = ">=", time = true, label = "开始时间")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS", timezone = "GMT+8")
	@Column(name = "CREATE_TIME")
	private Instant createTime;
	@JsonIgnore
	@ManyToOne
	@JoinColumn(name = "UPPER_ID")
	private DepartmentInfo upper;

	public String getDeptName() {
		return deptName;
	}

	public void setDeptName(String deptName) {
		this.deptName = deptName;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public Instant getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Instant createTime) {
		this.createTime = createTime;
	}

	public DepartmentInfo getUpper() {
		return upper;
	}

	public void setUpper(DepartmentInfo upper) {
		this.upper = upper;
	}

	public String getDeptCode() {
		return deptCode;
	}

	public void setDeptCode(String deptCode) {
		this.deptCode = deptCode;
	}

	public Map<String, String> getDepartment() {
		if (!ObjectUtils.isEmpty(this.upper)) {
			Map<String, String> department = new HashMap<String, String>();
			department.put("deptId", this.upper.getId());
			department.put("deptName", this.upper.getId());
			return department;
		}
		
		return null;
	}

}
